#-----------------------------------
# Name: Shane Corley
# Project Madlibs.py
# Period: 1
# Start Date: 9/24/2013
# Last Revision Date: 9/24/2013
# Version: 1.0.0
#----------------------------
import os, string
import math 

swearList = [
			 "dumb",
			 "stupid",
			 "retard",
			 "faggot",
			 "cunt",
			 "bitch",
			 "fuck",
			 "shit",
			 "homo",
			 "cock",
			 "dick",
			 "penis",
			 "vagina",
			 "tits",
			 "tit",
			 "titties",
			 "faggoty fuck faggot nigger",
			 "nigger",
			 "nigga",
			 "niggers",
			 "niggas",
			 "shitface",
			 "fuckface",
			 "ass",
			 "dumbass",
			 "motherfucker",
			 "mothafucker",
			 "motherfucka",
			 "mothafucka",
			 "dildo",
			 "dildos",
			 "homos",
			 "masturbation",
			 "jizz",
			 "semen",
			 "sex",
			 "cum",
			 "cumface",
			 "cumshot",
			 "ejaculate",
			 "ejaculates",
			 "jackoff",
			 "anal",
			 "analsex",
			 "asshole",
			 "goddamit",
			 "goddamnit",
			 "erection",
			 "boner",
			 "cumming",
			 "blowjob",
			 "handjob",
			 "rimjob",
			 "vibrator",
			 "vibrators",
			 "bigandblack",
			 "hardlongandthick",
			 "twat",
			 "twats",
			 "pussy",
			 "pussies",
			 "pussyfaggot",
			 "whore",
			 "whores",
			 "hoe",
			 "hoes",
			 "slut",
			 "sluts",
			 "boner",
			 "clit",
			 "poontang",
			 "queef",
			 "rimjob",
			 "feltch",
			 "minge",
			 "spooge",
			 "smegma",
			 "pecker",
			 "boobs",
			 "piss",
			 "twat",
			 "taint",
			 "pubes",
			 "prick",
			 "hard-on",
			 "turd",
			 "nuts",
			 "nutsack",
			 "shitfaced",
			 "cocksucker",
			 "asscrack",
			 "buttcrack",
			 "clusterfuck",
			 "douchebag",
			 "dickhead",
			 "fuckface",
			 "shithead",
			 "buttfuck",
			 "dipshit",
			 "asshat",
			 "bumblefuck",
			 "cameltoe",
			 "dumbfuck",
			 "dumbshit",
			 "dumshit",
			 "dyke",
			 "fudgepacker",
			 "fucktard",
			 "fuckin",
			 "fagtard",
			 "feltch",
			 "faggotcock",
			 "fatass",
			 "flamer",
			 "gringo",
			 "gooch",
			 "humping",
			 "hard on",
			 "jackass",
			 "jigaboo",
			 "jagoff",
			 "kootch",
			 "lesbo",
			 "lezzie",
			 "lesbian",
			 "muff",
			 "niglet",
			 "penisfucker",
			 "penispuffer",
			 "penisbanger",
			 "poonany",
			 "punta",
			 "queer",
			 "renob",
			 "suckass",
			 "skank",
			 "skeet",
			 "smeg",
			 "snatch",
			 "sandnigger",
			 "sand nigger", 
			 "titfuck",
			 "tittyfuck",
			 "twats",
			 "twatwaffle",
			 "twatlips",
			 "thundercunt",
			 "unclefucker",
			 "vjayjay",
			 "va-j-j",
			 "whorebag",
			 "wankjob",
			 "wank",
			 "schlong"
			 
			 
			 
			
		
			 
			 
			 
			 ]
			 
bgColor = '0'
txtColor = 'F'

def getMenuOption(maxOptions):
	option = ""
	goodOption = False
	while not goodOption:
		option = raw_input("Enter a number or S or Q> ")
		option = option.upper()
		if option == 'S':
			goodOption = True
		elif option == 'Q' :
			goodOption = True
		elif option == 'X' :
			goodOption = True
		elif option == "":
			pass
		else:
			isNum = True
			for character in option:
				if character not in "0123456789":
					isNum = False
			if isNum:
				if int(option) <= 0:
					isNum = False
				elif int(option) > maxOptions:
					isNum = False
			if isNum:
				goodOption = True
			else:
				print "Please type a number!"
		if not goodOption:
			print "Invalid Choice, please try again. "
	return option

def menu():
	print "Welcome to Madlibs"
	print "Please Select an Option:"
	print " [1] The Dumb Kid"
	print " [2] The Chase"
	print " [3] The Omegle Killer"
	print " [S] Settings"
	print " [Q] Quit"
	print " [X] Don't Press This Ever!!!"
	option = getMenuOption(3)
	return option

def getWord(prompt):
	word = ""
	goodWord = False
	while not goodWord:
		word = raw_input(prompt)
		if word.lower() not in swearList:
			goodWord = True
		else:
			print "Naughty user...please be polite!"
		if word.isdigit():
			goodWord = False
			print "That's not a word."
		if word == "":
			goodWord = False
			print "You've got to type something retard"
		
		if not goodWord:
			print "Please try again."
	return word
def getArticle(prompt):
	word = ""
	goodWord = False
	while not goodWord:
		word = raw_input(prompt)
		if word.lower() not in swearList:
			goodWord = True
		else:
			print "Naughty user...please be polite!"
		
		if word[0] in ["a","e","i","o","u"]:
				word = "an " + word
		else:
			word = "a " + word
		if word.isdigit():
			goodWord = False
			print "That's not a word."
		if word == "":
			goodWord=False
			print "You've got to type something retard"
		
		if not goodWord:
			print "Please try again."
	return word
def getNumber(prompt, min = "", max = ""):
		num = ""
		goodNumber = False
		while not goodNumber:
			num = raw_input(prompt)
			isNum = True
			for digit in num:
				if digit not in ".0123456789":
					isNum = False
			if isNum:
				if min != "":
					if float(num) < min:
						isNum = False
				if max != "":
					if float(num) > max:
						isNum = False
			if num == "":
				isNum = False
				print "You've got to type something retard"			
			if isNum:
				goodNumber = True
			else:
				print "Please enter a valid number"
		return num
def getMoney(prompt, min = "", max = ""):
		num = ""
		goodNumber = False
		while not goodNumber:
			num = raw_input(prompt)
			
			
			isNum = True
			for digit in num:
				if digit not in ".0123456789":
					isNum = False
			if isNum:
				if min != "":
					if float(num) < min:
						isNum = False
				if max != "":
					if float(num) > max:
						isNum = False
			if num == "":
				isNum = False
				print "You've got to type something retard"
			if isNum:
				goodNumber = True
				num = "{0:.2f}".format(float(num))
				num = "$" + num
			else:
				print "Please enter a valid number"
		return num
def getwholeNum (prompt, min = "", max = ""):
	num = ""
	goodNumber = False
	while not goodNumber:
		num = raw_input(prompt)
		isNum = True
		for digit in num:
			if digit not in "0123456789":
				isNum = False
		if isNum:
				if min != "":
					if float(num) < min:
						isNum = False
				if max != "":
					if float(num) > max:
						isNum = False
		if num == "":
				isNum = False
				print "You've got to type something retard"
		if isNum:
				goodNumber = True
		else:
				print "Please enter a whole number within the parameters"
	return num
					
def getColor(prompt):
	colors = ["black",
			  "blue",
			  "green",
			  "bright white",
			  "light red",
			  "red"]
	opt = ""
	goodColor = False
	while not goodColor:
		opt = raw_input(prompt)
		if opt.lower() in colors:
			goodColor = True
	if opt == "black":
		color = '0'
	elif opt == 'blue':
		color = '1'
	elif opt == 'green':
		color = '2'
	elif opt == 'bright white':
		color = 'F'
	elif opt == 'light red':
		color = 'C'
	elif opt == 'red':
		color = '4'
	return color
def getTime(prompt):
	time=""
	goodtime= False 
	while not goodtime:
		time= raw_input(prompt)
		#print time
		if 4 <= len(time) <= 5:
			if ":" in time:
				timeList = time.split(":")
				if timeList[0].isdigit():
					if int(timeList[0]) in [1,2,3,4,5,6,7,8,9,10,11,12]:
						if len(timeList[1]) == 2:
							if timeList[1][0] in "012345":
								if timeList[1][1] in string.digits:
									goodtime = True
		elif 1 <= len(time) <= 2:
			if time.isdigit():
				if int(time) in [1,2,3,4,5,6,7,8,9,10,11,12]:
					time += " o'clock"
					goodtime = True
		if not goodtime:
			print "Please enter a valid time"
	return time
		  
				
					
def story1():
	Name1 = getWord("Enter a name: ")
	Place1 = getWord("Enter a city: ")
	Noun1 = getArticle ("Enter a noun: ")
	Time1 = getTime ("Enter a time: ")
	Verb1 = getWord ("Enter a verb: ")
	Noun2 = getWord ("Enter a loud noise: ")
	Verb2 = getWord ("Enter a verb in the past tense: ")
	Num1 = getwholeNum ("Enter a number: ")
	Verb3 = getWord ("Enter a verb: ")
	Num2 = getMoney ("Enter a number: ")
	
	story = "It was just another school day for "
	story += Name1 + ". "
	story +=  "He found out his friend was going to " + Place1 
	story += " for the weekend. He decided to use his house while him and his parents were gone. "
	story += Name1 + " was planning on throwing " + Noun1 + " in his friend's house. "
	story += "It was " + Time1 + " and " + Name1 + " went to his house ready to "
	story += Verb1 + ". " + Name1 + " didn't account for the neighbors. Due to the loud "
	story += Noun2 + " the neighbors called the cops. " + Name1 + " didn't know what to do "
	story += "so he " + Verb2 + "."
	story += " When " + Name1 + " looked out the window he saw " + Num1
	story += " cop cars."
	story += " That's when " + Name1 + " decided to " + Verb3 + ", but it was too late. "
	story += Name1 + " was caught and had to pay a fine of " + Num2 + "."
	#story += 
	print story

def story2():
	Name1 = getWord("Enter a name: ")
	Num1 = getwholeNum("Enter a number between 100 and 200: ", 100, 200)
	Time1= getTime("Enter a time: ")
	Num2 = getwholeNum("Enter a number between 2 and 60: ", 2, 60)
	Num3 = getwholeNum("Enter a number: ")
	Adj1 = getWord ("Enter an adjective: ")
	Noun1 = getArticle ("Enter a noun: ")
	Num4 = getwholeNum ("Enter a number: ")
	Verb1 = getWord ("Enter a verb: ")
	Num5 = getwholeNum ("Enter a number: ")
	
	
	
	story = Name1 + " was driving down 89 in the middle of the night. "
	story += "He decided to crack open a couple beers. In total he had " + Num3 + ". "
	story += "He was feeling very " + Adj1 + " and decided to have some fun. "
	story += Name1 + " started to go " + Num1 + " mph. "
	story += "It was now " + Time1 + ". "
	story += "It only took " + Num2 + " minutes before the cops were on "
	story += Name1 + "'s tail. "
	story += "In response, " + Name1 + " decided to throw " + Noun1 + " out the back window. "
	story += "In no time at all " + Name1 + " had " + Num4 + " cop cars behind him. "
	story += "Up ahead he saw a spike strip. "
	story += "That's when " + Name1 + " decided to " + Verb1 + ". "
	story += Name1 + " was eventually caught and had to serve " + Num5 + " days in prison."
	print story

def story3():

	
	Num1 = getwholeNum("Enter a number: ")
	Num2 = getwholeNum("Enter a number between 20 and 100: ",20,100)
	Body1 = getWord("Enter a body part: ")
	Object1 = getArticle("Enter an object: ")
	Time1 = getTime("Enter a time: ")
	Object2 = getArticle("Enter an object: ")
	Num3 = getwholeNum("Enter a number: ")
	Animal1 = getArticle("Enter an animal: ")
	Adj1 = getWord("Enter an adjective: ")
	Object3 = getArticle("Enter a big object: ")
	
	story= "One night a group of friends got together to do some nice omegling. "
	story += "They were on Omegle for " + Num1 + " hours."
	story += " That's when they started to get bored and decided to insult everyone they saw. "
	story += "That's when they saw a man probably about " + Num2 + " years old. "
	story += "They started making fun of the man's " + Body1 + ". "
	story += "The man got so angry that he looked the kids right in the eyes, pulled out " + Object1
	story += ", and told the kids he was coming to get them."
	story += " It was now " + Time1 + " and they heard a knocking on the door. "
	story += "They looked outside and saw the Omegle man standing out there with " + Object2 + ". "
	story += "That's when the man broke the door down with the " + Object2.split(' ')[1] + " and started chasing the kids. "
	story += "The chase went on for " + Num3 + " hours. "
	story += "Finally the man caught one of the friends and was about to finish him. That's when " + Animal1
	story += " jumped on the man and knocked him out. "
	story += "The kids were very " + Adj1 + ". "
	story += "They took the man's body and threw it into " + Object3 + ". "
	print story


def settings():
	txtColor = getColor("Enter Text Color: ")
	bgColor = getColor("Enter Backgound Color: ")
	if txtColor != bgColor:
		os.system("color " + bgColor + txtColor)
def pi():
	def calcPi():
		q, r, t, k, n, l = 1, 0, 1, 1, 3, 3
		while True:
			if 4*q+r-t < n*t:
				yield n
				nr = 10*(r-n*t)
				n  = ((10*(3*q+r))//t)-10*n
				q  *= 10
				r  = nr
			else:
				nr = (2*q+r)*l
				nn = (q*(7*k)+2+(r*l))//(t*l)
				q  *= k
				t  *= l
				l  += 2
				k += 1
				n  = nn
				r  = nr
 
	import sys
	pi_digits = calcPi()
	i = 0
	for d in pi_digits:
		sys.stdout.write(str(d))
		i += 1
		if i == 40: print(""); i = 0


	
def run():
	choice = ""
	while choice != 'Q':
		choice = menu()
		if choice == '1':
			story1()
		elif choice == '2':
			story2()
		elif choice == '3':
			story3()
		elif choice == 'S':
			settings()
		elif choice == 'Q':
			print " Goodbye"
			os.system("color " + bgColor + txtColor)
			raw_input("Press enter to exit")
		elif choice == 'X':
			pi()
		else:
			print "Something terrible has happened...go yell at the programmer"
	
run()
		
		
		
		
		
		
		